/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.st.utils

import org.grails.plugins.springsecurity.service.AuthenticateService

/**
 *
 * @author ddevore
 */
class SecurityUtil {


    static boolean isLoggedIn(AuthenticateService authenticateService) {
        println "in abstract security " + authenticateService.isLoggedIn()
        return authenticateService.isLoggedIn()
    }

    static boolean isAdmin(AuthenticateService authenticateService) {
        return authenticateService.ifAnyGranted("ROLE_ADMIN")
    }

    static boolean isPowerUser(AuthenticateService authenticateService) {
        return authenticateService.ifAnyGranted("ROLE_POWERUSER") ||
                SecurityUtil.isAdmin(authenticateService)
    }

    static boolean isApprover(AuthenticateService authenticateService) {
        return authenticateService.ifAnyGranted("ROLE_MANAGER")
    }

    static boolean isCompanyAdmin(AuthenticateService authenticateService) {
        return authenticateService.ifAnyGranted("ROLE_COMPANY_ADMIN")
    }

    static boolean isConsultant(AuthenticateService authenticateService) {
        return authenticateService.ifAnyGranted("ROLE_CONSULTANT")
    }

    static long getUserId(AuthenticateService authenticateService) {
        return authenticateService.userDomain().id
    }

    static Object getUser(AuthenticateService authenticateService) {
        return authenticateService.userDomain()
    }
}

